package org.beetl.sql.test.mysql;

import org.beetl.sql.core.*;
import org.beetl.sql.core.db.DBStyle;
import org.beetl.sql.core.db.MySqlStyle;
import org.beetl.sql.ext.DebugInterceptor;
import org.beetl.sql.ext.gen.GenConfig;


/**
 * Created by maliqiang on 2017/1/23.
 */
public class GeneratorTool {
    public static void main(String[] args) {
        String url="jdbc:mysql://localhost:3306/beetl";
        String driver = "com.mysql.jdbc.Driver";
        String userName = "root";
        String password = "root";
//        testConnect(driver,url,userName,password);
        generatePojo(driver,url,userName,password);
    }


   public static void generatePojo(String driver,String url,String userName,String  password) {
       ConnectionSource source = ConnectionSourceHelper.getSimple(driver, url, userName, password);
       DBStyle mysql = new MySqlStyle();
       // sql语句放在classpagth的/sql 目录下
       SQLLoader loader = new ClasspathLoader("/sql");
       // 数据库命名跟java命名一样，所以采用DefaultNameConversion，还有一个是UnderlinedNameConversion，下划线风格的
       //所以采用DefaultNameConversion nc = new  所以采用DefaultNameConversion();
       DefaultNameConversion dc = new DefaultNameConversion();
       // 最后，创建一个SQLManager,DebugInterceptor 不是必须的，但可以通过它查看sql执行情况
       SQLManager sqlManager = new SQLManager(mysql,loader,source,dc,new Interceptor[]{new DebugInterceptor()});

       try {
//           sqlManager.genPojoCodeToConsole("com.mark","user");
//           sqlManager.genSQLTemplateToConsole("user");
           GenConfig config = new GenConfig();
//           config.setClzNameUpper(false);
           sqlManager.genPojoCode("user","com.mark", config);
       } catch (Exception e) {

           e.printStackTrace();
       }
   }
}
